<?php
    include('session.inc');
    require_once('funct.inc');
    include 'color_style.php';
    include LANGUAGE;
    if(!GetAdminID($ID)){echo LOGIN_ERR;exit;}
    if(!Right_Check(5)){header('Location:error.php');exit;}
?>
<?php
    require_once('OpenDB.inc');


    $A_Name     =$_REQUEST["A_Name"];
    $A_Surname  =$_REQUEST["A_Surname"];
    $A_Nick     =$_REQUEST["A_Nick"];
    $A_Passwd   =$_REQUEST["A_Passwd"];
    $A_Passwd2  =$_REQUEST["A_Passwd2"];

    GetAdminID($AdminID);

    if (!OpenDB()){echo OPEN_DB_ERR; break;}
	print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">";
    print "<html>";
    print "<head>";
    include 'html_style.php';
    print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset="._CHARSET_.";\" />";
    print "</head>";
    print "<body bgcolor=\"".Background_Color."\">";

    if (($A_Nick!="") AND  ($A_Passwd!="") AND ($A_Passwd==$A_Passwd2))
    $SQL=1;
    else
    $SQL=0;


    if ($SQL)
    {
         if(!SQL_Control_NEW_Duplicate($A_Nick)){
              $SQL=   "INSERT INTO admins (A_Name,A_Surname,A_Nick,A_Passwd,A_Rights)
                       VALUES ('".$A_Name."', '".$A_Surname."', '".$A_Nick."', '".sha1($A_Passwd)."','/"
                       .$_REQUEST[right_products]
                       .$_REQUEST[right_orders]
                       .$_REQUEST[right_discuss]
                       .$_REQUEST[right_users]
                       .$_REQUEST[right_admin]
                       .$_REQUEST[right_statistic]
                       ."')";

              mysql_query($SQL);
		//print "T�to funkcia je v testovacom prostred� zablokovan�!";
		

              print "<center><h3><b>".A_NOVY_ADMIN."</b></h3></center>";
              print "<form action=\"adm_acount_management.php\" target=\"place\" method=\"post\">";
                            print "<center><input type=\"submit\" value=\"".A_NASPAT."\" style=\"width :80px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" /></center>";
              print "</form>";
           }
           else{
                print  "<script language=\"JavaScript\">
                <!--
                  window.alert(\"".A_ALERT." '".$_REQUEST["A_Nick"]."'\");
                  //-->
                </script>";
                $SQL=0;
           }
    }
    if (!$SQL){
        print"<form action=\"adm_insert_acount.php\" target=\"place\" method=\"post\">
                <table>
                    <tr>
                        <td> ".A_MENO.": </td>
                        <td> <input type=\"text\" name=\"A_Name\" value=\"".$A_Name."\" /> </td>
                    </tr>
                    <tr>
                        <td> ".A_PRIEZVISKO.": </td>
                        <td> <input type=\"text\" name=\"A_Surname\" value=\"".$A_Surname."\" /> </td>
                    </tr>
                    <tr>
                        <td> ".A_NICK.": </td>
                        <td> <input type=\"text\" name=\"A_Nick\" value=\"".$A_Nick."\" /> </td>
                    </tr>
                    <tr>
                        <td> ".A_HESLO.": </td>
                        <td> <input type=\"password\" name=\"A_Passwd\" value=\"\" /> </td>
                    </tr>
                    <tr>
                        <td> ".A_HESLO_OPAKUJ.": </td>
                        <td> <input type=\"password\" name=\"A_Passwd2\" value=\"\" /> </td>
                    </tr>
                    <tr>
                        <td colspan=\"2\"> <br /><b><u> ".A_RULES_KOMENTAR.": </u></b> </td>
                    </tr>
                    <tr>
                        <td colspan=\"2\"> <input type=\"checkbox\" value=\"1/\" name=\"right_products\" /> ".A_RULES1." </td>
                    </tr>
                    <tr>
                        <td colspan=\"2\"> <input type=\"checkbox\" value=\"2/\" name=\"right_orders\" /> ".A_RULES2." </td>
                    </tr>
                    <tr>
                        <td colspan=\"2\"> <input type=\"checkbox\" value=\"3/\" name=\"right_discuss\" /> ".A_RULES3." </td>
                    </tr>
                    <tr>
                        <td colspan=\"2\"> <input type=\"checkbox\" value=\"4/\" name=\"right_users\" /> ".A_RULES4." </td>
                    </tr>
                    <tr>
                        <td colspan=\"2\"> <input type=\"checkbox\" value=\"5/\" name=\"right_admin\" /> ".A_RULES5." </td>
                    </tr>";
               if(file_exists("modules/top_products/top_products.php") OR file_exists("modules/top_user/top_user.php") OR file_exists('modules/valuations/adm_product_valuations.php'))
			            print "<tr><td colspan=\"2\"> <input type=\"checkbox\" value=\"6/\" name=\"right_statistic\" /> ".A_RULES6." </td></tr>";
               print "<tr>
                        <td colspan=\"2\">
                        <input type=\"submit\" value=\"".A_ULOZIT."\" style=\"width :300px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                        </td>
                    </tr>
            </form>";
    }


    print "</body>";
    mysql_close();
print "</html>";
?>
